//package miniparser;
//import java_cup.runtime.ComplexSymbolFactory;

//import System.IO.*;
//import minijava.*;
public class _Main {


    /**
      * Runs the parser on an input file.
      *
      *
      * @param argv   the command line, argv[1] is the filename to run
      *               the parser on, argv[0] determines the compiler mode
      */
    public static void main(String[] argv) {
        Lexer scanner = null;
        ComplexSymbolFactory csf = new ComplexSymbolFactory();
        try {
            scanner = new Lexer(new System.IO.StreamReader(argv[1]), csf);
        }
        catch (FileNotFoundException e) {
            System/*error*/.Console.WriteLine("File not found : \"" + argv[1] + "\"");
            ////System.exit(1);
        }
        catch (IndexOutOfRangeException e) {
            System/*error*/.Console.WriteLine("Usage : java Main <MODE> <inputfile>");
            System/*error*/.Console.WriteLine("  with MODE ::= -jvm | -syntax | -cfg");
            ////System.exit(1);
        }

        try {
            Parser p = new Parser(scanner, csf);
            Program result = (Program)p.parse().value;
            if (argv[0].Equals("-jvm")) {
                MiniJVMGenerator jvm = new MiniJVMGenerator(argv[1]);
                result.accept(jvm);
                jvm.flush();
            }
            if (argv[0].Equals("-syntax")) {
                SyntaxTreeGenerator syntax = new SyntaxTreeGenerator(argv[1]);
                result.accept(syntax);
                syntax.flush();
            }
            if (argv[0].Equals("-cfg")) {
                CFGGenerator syntax = new CFGGenerator(argv[1]);
                result.accept(syntax);
                syntax.flush();
            }
        }
        catch (System.IO.IOException e) {
            System/*error*/.Console.WriteLine("An I/O error occured while parsing : \n" + e);
            ////System.exit(1);
        }
    }
}




